const Utils = (function () {



    //验证码
    const randomCode = (n = 4) => {
        var str = ""
        for (var i = 0; i < n; i++) {
            if (Math.random() > 0.5) {
                var num = (parseInt(Math.random() * 26) + 97);

                str += String.fromCharCode(num)
            } else {
                str += parseInt(Math.random() * 10)
            }
        }
        return str;
    }
    //验证方法
    const validate = (o, reg, msg) => {
        var str = o.value;
        var status = reg.test(str);
        if (status) {
            o.nextElementSibling.innerHTML = "<span ></span>"
        } else {
            o.nextElementSibling.innerHTML = "<span ></span>" + msg;
        }

        return status
    }

    const getFormData = (o) => {
        var User = {};
        Array.from(o).forEach(item => {
            if (item.name != "" || item.name != "code") {
                User[item.name] = item.value;
            }
            console.log(o);
        })
        return User;

    }
    return {

        randomCode,
        validate,
        getFormData
    }

})()